<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- 引入 Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<title>数据列表</title>
<style>
#myInput {
	background-image: url('https://static.runoob.com/images/mix/searchicon.png'); /* 搜索按钮 */
	background-position: 10px 12px; /* 定位搜索按钮 */
	background-repeat: no-repeat; /* 不重复图片*/
	width: 50%;
	font-size: 16px; /* 加大字体 */
	padding: 12px 20px 12px 40px;
	border: 1px solid #ddd;
	margin-bottom: 12px;
	display:inline;
}
#header {
	border-bottom:#000 medium dashed;
}
#container {
}
.item {
	border-bottom:#000 thin dotted;
}
</style>
</head>

<body>
<div id="header">
  <input type="text" id="myInput" onkeyup="myFunction()" style="margin-left:20px" placeholder="搜索...">
  <span>
  <input type="button" value="搜索" class="btn btn-default" style="margin-left:40px"/>
  </span> <span>
  <input type="button" value="添加数据" class="btn btn-default" onclick="addData()" style="margin-left:40px"/>
  </span> </div>
<div id="container">
  <div class="item">
    <div><span style="margin-left:20px">数据一</span> <span>
      <button id="modify" style="margin-left:40px" class="btn btn-default"  data-toggle="collapse" 
    data-target="#info">修改</button>
      </span> <span>
      <button  style="margin-left:40px" class="btn btn-default" >删除 </button>
      </span> 
      </div>
    <div id="info" class="collapse" role="form">
      <form class="form-horizontal" style="width:700px">
        <div class="form-group">
          <label class="control-label col-sm-2" for="name">主键：</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" id="name" value="xxx" />
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-sm-2" for="name">值：</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" id="name" value="xxxxx" />
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-sm-2" for="name">标签：</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" id="name" value="xxxx" />
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-sm-2" for="name">种类：</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" id="name" value="xxx" />
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-sm-2" for="name">排序：</label>
          <div class="col-sm-10">
            <input type="text" class="form-control" id="name" value="xxx" />
          </div>
        </div>
        <div class="form-group">
          <label class="control-label col-sm-2" for="name">备注：</label>
          <div class="col-sm-10">
            <textarea type="text" class="form-control" id="name">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</textarea>
          </div>
        </div>
        <div class="form-group" style="margin:0 auto;display:block; width:100px">
        <button  class="btn btn-default"  id="ok">保存</button>
        </div>
      </form>
    </div>
  </div>
</div>
</body>
<script>
//页面加载
$().ready(function()
{
	//需要传递当前用户数据
	//获取当前用户的信息
	var user_id=$.cookie("user_id");
	var password=$.cookie("password");
	$.post("/ulms_project/dict/query",{user_id:user_id,password:password},function(data)
	{
		var str="";
		$(data).each(function()
		{
			str+='<div class="item">'+
    '<div><span style="margin-left:20px">'+this.name+'</span> <span>'+
      '<button  style="margin-left:40px" class="btn btn-default"  data-toggle="collapse" '+
    'data-target="#info_'+this.id+'">修改</button>'+
      '</span> <span>'+
      '<button  style="margin-left:40px" class="btn btn-default" >删除 </button>'+
      '</span>'+ 
      '</div>'+
    '<div id="info_'+this.id+'" class="collapse" role="form">'+
      '<form class="form-horizontal" style="width:700px">'+
        '<div class="form-group">'+
          '<label class="control-label col-sm-2" for="name">主键：</label>'+
          '<div class="col-sm-10">'+
            '<input type="text" class="form-control" id="primariyKey_'+this.id+'" value="'+this.iod+'" />'+
          '</div>'+
        '</div>'+
        '<div class="form-group">'+
          '<label class="control-label col-sm-2" for="name">值：</label>'
          '<div class="col-sm-10">'
            '<input type="text" class="form-control" id="value_'+this.id+'" value="'+this.value+'" />'+
          '</div>'+
        '</div>'+
        '<div class="form-group">'+
          '<label class="control-label col-sm-2" for="name">标签：</label>'+
          '<div class="col-sm-10">'+
            '<input type="text" class="form-control" id="label_'+this.id+'" value="'+this.label+'" />'+
          '</div>'+
        '</div>'+
        '<div class="form-group">'+
          '<label class="control-label col-sm-2" for="name">种类：</label>'+
          '<div class="col-sm-10">'+
            '<input type="text" class="form-control" id="type_'+this.id+'" value="'+this.type+'" />'+
          '</div>'+
        '</div>'+
        '<div class="form-group">'+
          '<label class="control-label col-sm-2" for="name">排序：</label>'+
          '<div class="col-sm-10">'+
            '<input type="text" class="form-control" id="sort_'+this.sort+'" value="'+this.sort+'" />'+
          '</div>'+
        '</div>'+
        '<div class="form-group">'+
          '<label class="control-label col-sm-2" for="name">备注：</label>'+
          '<div class="col-sm-10">'+
            '<textarea type="text" class="form-control" id="remark_'+this.remark+'">'+this.remark+'</textarea>'+
         ' </div>'+
       '</div>'+
       ' <div class="form-group" style="margin:0 auto;display:block; width:100px">'+
        '<button  class="btn btn-default"  onclick="modify()" data_id="'+this.id+'">保存</button>'+
        '</div>'+
      '</form>'+
    '</div>'+
 ' </div>';
		});
		$("#container").html(str);
	});
});

//搜索功能
function query()
{
	//可以根据类型查找
	var type=$("myInput").val();
	var str="";
	$.post("/ulms_project/dict/queryByType",{type:type},function(data)
	{
		$(data).each(function()
		{
			str+='<div class="item">'+
    '<div><span style="margin-left:20px">'+this.name+'</span> <span>'+
      '<button  style="margin-left:40px" class="btn btn-default"  data-toggle="collapse" '+
    'data-target="#info_'+this.id+'">修改</button>'+
      '</span> <span>'+
      '<button  style="margin-left:40px" class="btn btn-default" >删除 </button>'+
      '</span>'+ 
      '</div>'+
    '<div id="info_'+this.id+'" class="collapse" role="form">'+
      '<form class="form-horizontal" style="width:700px">'+
        '<div class="form-group">'+
          '<label class="control-label col-sm-2" for="name">主键：</label>'+
          '<div class="col-sm-10">'+
            '<input type="text" class="form-control" id="primariyKey_'+this.id+'" value="'+this.iod+'" />'+
          '</div>'+
        '</div>'+
        '<div class="form-group">'+
          '<label class="control-label col-sm-2" for="name">值：</label>'
          '<div class="col-sm-10">'
            '<input type="text" class="form-control" id="value_'+this.id+'" value="'+this.value+'" />'+
          '</div>'+
        '</div>'+
        '<div class="form-group">'+
          '<label class="control-label col-sm-2" for="name">标签：</label>'+
          '<div class="col-sm-10">'+
            '<input type="text" class="form-control" id="label_'+this.id+'" value="'+this.label+'" />'+
          '</div>'+
        '</div>'+
        '<div class="form-group">'+
          '<label class="control-label col-sm-2" for="name">种类：</label>'+
          '<div class="col-sm-10">'+
            '<input type="text" class="form-control" id="type_'+this.id+'" value="'+this.type+'" />'+
          '</div>'+
        '</div>'+
        '<div class="form-group">'+
          '<label class="control-label col-sm-2" for="name">排序：</label>'+
          '<div class="col-sm-10">'+
            '<input type="text" class="form-control" id="sort_'+this.sort+'" value="'+this.sort+'" />'+
          '</div>'+
        '</div>'+
        '<div class="form-group">'+
          '<label class="control-label col-sm-2" for="name">备注：</label>'+
          '<div class="col-sm-10">'+
            '<textarea type="text" class="form-control" id="remark_'+this.remark+'">'+this.remark+'</textarea>'+
         ' </div>'+
       '</div>'+
       ' <div class="form-group" style="margin:0 auto;display:block; width:100px">'+
        '<button  class="btn btn-default"  onclick="modify()" data_id="'+this.id+'">保存</button>'+
        '</div>'+
      '</form>'+
    '</div>'+
 ' </div>';
		});
		$("#container").html(str);
	});
}

//添加数据功能
function addData()
{
	window.open("addData.html");
}

//修改数据功能
function modify()
{
	//获取修改后的数据
	var data_id= $(this).attr("data_id");
	var primaryKey=$("#primaryKey_"+data_id).val();
	var value=$("#value_"+data_id).val();
	var label=$("#label_"+data_id).val();
	var type=$("#type_"+data_id).val();
	var mySort=$("#mySort_"+data_id).val();
	var remark=$("#remark_"+data_id).val();
	
	$.post("/ulms_project/dict/modify",{data_id:data_id,primaryKey:primaryKey,value:value,label:label,type:type,mySort:mySort,remark:remark},function(data)
	{
		alert("修改数据成功！！");
	});
}

//删除数据功能
function remove()
{
	var data_id=$(this).attr("data_id");
	$.post("/ulms_project/dict/modify",{data_id:data_id},function(data)
	{
		alert("删除数据成功！！");
	});
}
</script>
</html>
